Ext.define('MetaData', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
	    , "FText"   //功能名称
	    , "FValue"   //权限值
	    , "FOrder"   //序号				
    ],
    idProperty: "Id"
});

Ext.define('SHApp.System.MetaData.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.system.grid',
    requires: ['SHApp.System.MetaData.Form'],
    dataModel: "MetaData",
    dataUrl:"api/metadata?format=json",
    firstLoad: true,
    sortInfield: 'FOrder', //排序字段
    isAsc: 'asc',     //升序还是降序
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [
            {
                text: "Id",
                flex: 1,
                dataIndex: 'Id',
                sortable: false,
                hidden: true
            }, {
                xtype: "rownumberer",
                width: 30
            }, {
                text: "功能名称",
                width: 200,
                dataIndex: 'FText',
                sortable: true
            }, {
                text: "权限值",
                width: 100,
                dataIndex: 'FValue',
                sortable: true
            }, {
                text: "序号",
                width: 100,
                dataIndex: 'FOrder',
                sortable: true,
                hidden: true
            }
		]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
		    '->', {
		        xtype: 'button',
		        text: '添加',
		        id: me.btnAddID,
		        iconCls: 'icon-btn-add',
		        handler: function () {
		            var win = me.getForm('SHApp.System.MetaData.Form');
		            //var fOrder = me.store.getTotalCount() + 1;
		            var maxOrder = me.store.max("FOrder"),
                        fOrder = 1;
		            if (maxOrder) {
		                fOrder += maxOrder;
		            }
		            win.loadRecord(new MetaData({ Id: null, FOrder: fOrder }));
		            win.Show("添加");
		        }
		    }, ' ', {
		        xtype: 'button',
		        disabled: true,
		        id: me.btnEditID,
		        text: '修改',
		        iconCls: 'icon-btn-edit',
		        handler: function () {
		            me.EditData(me.getForm('SHApp.System.MetaData.Form'));
		        }
		    }, ' ', {
		        xtype: 'button',
		        disabled: true,
		        id: me.btnDeleteID,
		        text: '删除',
		        iconCls: 'icon-btn-delete',
		        handler: function () {
		            me.DeleteData();
		        }
		    }
        ]
    }
})

